
from django.test import TestCase

# Create your tests here.



class  TestTStudent:
    # 让当前py文件连接到数据库
    @staticmethod
    def f_init():
        import os
        os.environ["DJANGO_SETTINGS_MODULE"] = "django08_01.settings"
        import django
        django.setup()
        pass

    @staticmethod
    def f_save():
        from app02.models import TStudent
        from django.db import connection

        v_tStudent=TStudent()
        v_tStudent.student_name='cjgong02'
        v_tStudent.student_sex='m'
        v_tStudent.save()                 #  把数据保存到表    insert into
        # 输出django所要执行的sql语句
        print(connection.queries)
        pass
    @staticmethod
    def f_select():
        from app02.models import TStudent
        from django.db import connection

        v_student:TStudent=TStudent.objects.get(student_id=1)

        print(v_student.student_id,v_student.student_name,v_student.student_sex)
        # 输出django所要执行的sql语句
        print(connection.queries)
        pass


    @staticmethod
    def f_update():
        from app02.models import TStudent
        from django.db import connection

        v_student:TStudent=TStudent.objects.get(student_id=1)

        v_student.student_sex='m'
        v_student.student_name='cjgong11'

        v_student.save()

        # 输出django所要执行的sql语句
        print(connection.queries)

        pass

    @staticmethod
    def f_delete():
        from app02.models import TStudent
        from django.db import connection

        v_student:TStudent=TStudent.objects.get(student_id=1)
        v_student.delete()

        # 输出django所要执行的sql语句
        print(connection.queries)
        pass

    pass

if __name__=='__main__':
    TestTStudent.f_init()
    # TestTStudent.f_save()
    TestTStudent.f_delete()

    pass